<template>
  <el-dialog
    title="课程评分排行榜"
    :visible="open"
    width="1200px"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    append-to-body
    @close="cancel()"
  >
    <el-table
      height="485"
      border
      v-loading="loading"
      :data="postList"
      ref="tableRef"
    >
      <el-table-column show-overflow-tooltip label="排名" align="center">
        <template slot-scope="scope">
          {{
            (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
          }}
        </template>
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="课程名称"
        align="center"
        prop="courseName"
      />
      <el-table-column
        show-overflow-tooltip
        label="综合评分"
        align="center"
        prop="courseStar"
      />
      <el-table-column
        show-overflow-tooltip
        label="评分人数"
        align="center"
        prop="evaluateNum"
      />
    </el-table>
    <div class="flexend trainerBox">
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>

    <div slot="footer" class="dialog-footer">
      <el-button v-preventReClick @click="cancel">关 闭</el-button>
    </div>
  </el-dialog>
</template>
    
    <script>
import { courseStarList } from "@/api/screen/courseLearningManagement";
export default {
  components: {},
  props: {
    open: Boolean,
  },
  data() {
    return {
      loading: false,
      postList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      total: 10,
    };
  },
  watch: {
    open: {
      handler(newVal) {
        if (newVal) {
          this.getList();
        }
      },
      immediate: true,
    },
  },
  methods: {
    async getList() {
      let res;
      try {
        this.loading = true;
        res = await courseStarList(this.queryParams);
        if (res.code == 200) {
          this.postList = res.rows;
          this.total = res.total;
          // 页面数据更新后，让表格滚动条回到顶部
          this.$nextTick(() => {
            if (this.$refs.tableRef) {
              this.$refs.tableRef.bodyWrapper.scrollTop = 0;
            }
          });
        }
      } finally {
        this.loading = false;
      }
    },
    // 取消按钮
    cancel() {
      this.$emit("update:open", false);
    },
  },
  created() {},
  mounted() {},
};
</script>
    <style scoped lang='scss'>
::v-deep .el-button:focus,
.el-button:hover {
  color: #ff6801;
  border-color: #ff6801;
  background-color: rgba($color: #ff6801, $alpha: 0.3);
}
</style>
    